package com.xiaoshuidi.cloud.module.finance.api.order;

import com.alibaba.fastjson.JSON;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.finance.api.order.dto.PayOrderCreateReqDTO;
import com.xiaoshuidi.cloud.module.finance.api.order.dto.PayOrderRespDTO;
import com.xiaoshuidi.cloud.module.finance.convert.order.PayOrderConvert;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.order.PayOrderDO;
import com.xiaoshuidi.cloud.module.finance.service.order.PayOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

/**
 * 支付单 API 实现类
 */
@RestController
@Slf4j
public class PayOrderApiImpl implements PayOrderApi {

    @Resource
    private PayOrderService payOrderService;

    @Override
    public CommonResult<Long> createOrder(PayOrderCreateReqDTO reqDTO) {
        log.info("创建订单APi{}==============================", JSON.toJSONString(reqDTO));
        return success(payOrderService.createPayFlow(reqDTO));
    }

    @Override
    public PayOrderRespDTO getOrder(Long id) {
        PayOrderDO order = payOrderService.getOrder(id);
        return PayOrderConvert.INSTANCE.convert2(order);
    }

}
